import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';
import 'package:sprintf/sprintf.dart';

import 'hr_logic.dart';

class HrPage extends StatelessWidget {
  ///心率设置页面
  HrPage({super.key});

  final logic = Get.put(HrLogic());
  final state = Get.find<HrLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.settings_hr.ts),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back())
      ),
      body: Padding(
        padding: EdgeInsets.only(left: 40.w, top: 80.h, right: 40.w),
        child: ListView(
          children: [
            Container(
              height: 175.h,
              padding: EdgeInsets.only(left: 59.w, right: 36.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20),
              ),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      LocaleKeys.settings_hr_enable.ts,
                      style: TextStyle(
                          fontSize: 42.sp, color: ColorConst.primaryFontColor),
                    ),
                    Transform.scale(
                        scale: 0.7,
                        child: Obx(() => CupertinoSwitch(
                            value: state.isHeartRate.value,
                            activeColor: ColorConst.accentColor,
                            onChanged: (value) {
                              logic.setHeartRateEnable(value);
                            })))
                  ]),
            ),
            Container(
              padding: EdgeInsets.only(left: 102.w, top: 39.h),
              child: Text(LocaleKeys.settings_hr_enable_tips.ts,
                  style: TextStyle(
                      fontSize: 42.sp, color: ColorConst.primaryFontColor)),
            ),
            SizedBox(height: 75.h),
            Ink(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20),
              ),
              child: InkResponse(
                splashColor: ColorConst.activeColor,
                borderRadius: BorderRadius.circular(20),
                highlightShape: BoxShape.rectangle,
                highlightColor: ColorConst.activeColor,
                containedInkWell: true,
                child: Container(
                  height: 247.h,
                  padding: EdgeInsets.only(left: 39.w, top: 48.h, right: 36.w),
                  child: Column(
                    children: [
                      Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              LocaleKeys.settings_hr_warning.ts,
                              style: TextStyle(
                                  fontSize: 42.sp,
                                  color: ColorConst.primaryFontColor),
                            ),
                            Expanded(child: Container()),
                            Obx(() => Text(
                              sprintf(
                                  LocaleKeys.settings_hr_scope_subtitle.ts, [
                                state.maxHeartRate.value,
                                state.minHeartRate.value
                              ]),
                              style: TextStyle(
                                  fontSize: 42.sp,
                                  color: ColorConst.primaryFontColor),
                            )),
                            SizedBox(width: 40.w),
                            const Icon(
                              Icons.arrow_forward_ios,
                              size: 14,
                            ),
                          ]),
                      SizedBox(height: 30.h),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          LocaleKeys.settings_hr_scope.ts,
                          style: TextStyle(
                              fontSize: 36.sp,
                              color: ColorConst.secondaryFontColor),
                        ),
                      ),
                    ],
                  ),
                ),
                onTap: () {
                  Get.toNamed("/device/settings/hr_warning");
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
